<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="google-site-verification" content="yaeorbXgKPwp5BDegBtAJEHYWFEFE-BViWTj74gJPrw" />
<!--  -->
<link href="/css/default.css" type="text/css" rel="stylesheet" />
<!--  -->
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="/lang/cn.js"></script>
<script type="text/javascript" src="/js/mac/core.min.js"></script>
<title>mac-message - 配置</title>
<meta name="description" content="mac-message activemq jms broker 消息中间件 消息中心" />
<meta name="keywords" content="mac-message activemq jms broker 消息中间件 消息中心 消息监控" />
<script type="text/javascript">
$(function(){
	function adjust(){
		var de = document.documentElement
			, ch = de.clientHeight, cw = de.clientWidth;
		$('#body').width(cw - 16);
	}
	$(window).resize(adjust);
	adjust();
});
</script>
</head>
<body>
<div id="head">
	<a href="/"><img src="/css/images/logo_s.png" alt="logo" /></a>
	<div class="title">BOARSOFT.COM</div>
	<div class="right">
		<div>
			<a href="/public/lang.php?l=en">English</a>
			|
			<a href="/public/lang.php?l=cn">简体中文</a>
			|
			<a href="http://activemq.apache.org/" target="_blank">ActiveMQ</a>
			|
			<a href="https://redis.io/" target="_blank">Redis</a>
			|
			<a href="http://www.jquery.com/" target="_blank">JQuery</a>
		</div>
	</div>
</div><div id="body">
	<div class="dir">
<h1>目录</h1>
<hr/>
<ul>
	<li><a href="./index.html">基本概念</a></li>
	<ul>
		<li><a href="./index.html#queue">消息队列与发件人队列</a></li>
		<li><a href="./index.html#adapter">输入输出适配器</a></li>
		<li><a href="./index.html#finder">过滤与分拣插件</a></li>
		<li><a href="./index.html#tq">目标队列</a></li>
		<li><a href="./index.html#rq">收件人队列</a></li>
		<li><a href="./index.html#converter">消息转换器</a></li>
		<li><a href="./index.html#finder">滤与分拣插件</a></li>
		<li><a href="./index.html#ack">收件人消息签收</a></li>
	</ul>
	<li><a href="./config.html">配置项</a></li>
	<ul>
		<li><a href="./config.html">基本配置</a></li>
		<li><a href="./config.html#queues">外置队列信息配置</a></li>
		<li><a href="./config.html#amqServer">服务端ActiveMQ配置</a></li>
		<li><a href="./config.html#amqClient">客户端ActiveMQ长连接配置</a></li>
	</ul>
	<li><a href="./demo.html">用法示例</a></li>
	<ul>
		<li><a href="./demo.html#rpc">基于RPC的收发</a></li>
		<li><a href="./demo.html#amq">ActiveMQ/JMS的收发</a></li>
		<li><a href="./demo.html#adapter">输入输出适配器</a></li>
		<li><a href="./demo.html#converter">消息转换器</a></li>
		<li><a href="./demo.html#finder">过滤与分拣插件</a></li>
		<li><a href="./demo.html#shard">简单水平分片</a></li>
	</ul>
	<li><a href="./monitor.html">可视化消息监控</a></li>
	<ul>
		<li><a href="./monitor.html">功能介绍</a></li>
	</ul>
	<li><a href="./advance.html">进阶应用</a></li>
	<ul>
		<li><a href="./advance.html#ack">收件人消息签收</a></li>
		<li><a href="./advance.html#converter">自定义消息转换器</a></li>
		<li><a href="./advance.html#interceptor">ActiveMQ消息拦截与转换</a></li>
		<li><a href="./advance.html#ack">收件人消息签收</li>
		<li><a href="./advance.html#finder">过滤与分拣插件</a></li>
		<li><a href="./advnace.html#shard">使用数据库中间件</a></li>
	</ul>
</ul>	</div>
	<div class="main">
		<div id="nav">
			<div id="nav_path">
				<a href="/">Home</a>
				&gt;
				<a href="/mac/message">mac-message</a>
				&gt;
				配置
			</div>
			<div id="nav_back">
				<a href="javascript:history.back()">后退</a>
				|
				<a href="/">上一级</a> &nbsp;&nbsp;
			</div>
			<div class="clear"></div>
		</div>
<h1>mac-message - 配置</h1>
<h2>基本配置</h2>
&nbsp;&nbsp;message.xml，此配置基本上相固定，只需要配置所用的消息队列
<xmp>
	<bean id="messageContext" class="com.boarsoft.message.core.MessageContext">
		<!-- 配置消息队列 -->
		<property name="targetQueueMap">
			<map>
				<!-- 消息队列queue1 -->
				<entry key="queue1">
					<bean class="com.boarsoft.message.bean.TargetMQ">
						<property name="code" value="queue1" />
						<property name="relay" value="true" />
					</bean>
				</entry>
				<!-- 用于接收签收回执的消息队列ack1 -->
				<entry key="ack1">
					<bean class="com.boarsoft.message.bean.TargetMQ">
						<property name="code" value="ack1" />
					</bean>
				</entry>
			</map>
		</property>
	</bean>

	<bean id="localMsgSvc2" class="com.boarsoft.message.core.MessageServiceImpl2">
		<property name="messageContext" ref="messageContext" />
		<!-- 作为消息中间件，不需要注入 serverMsgSvc -->
		<!-- <property name="serverMsgSvc" ref="serverMsgSvc" /> -->
	</bean>

	<bean id="localMsgSvc1" class="com.boarsoft.message.core.MessageServiceImpl1">
		<property name="messageContext" ref="messageContext" />
		<!-- <property name="siblingMsgSvc" ref="siblingMsgSvc" /> -->
		<property name="localMsgSvc2" ref="localMsgSvc2" />
	</bean>

	<bean id="messenger" class="com.boarsoft.message.core.Messenger">
		<property name="localMsgSvc1" ref="localMsgSvc1" />
	</bean>

	<bean id="messageCore" class="com.boarsoft.message.core.MessageCore">
		<property name="threadPool" ref="threadPool" />
	</bean>
	
	<!-- 用于消息收发统计，可选 -->
	<bean id="messageServerStat" class="com.boarsoft.message.core.MessageStatServiceImpl">
		<property name="messageContext" ref="messageContext" />
	</bean>
</xmp>
<h2><a name="queues"></a>外置队列信息配置</h2>
&nbsp;&nbsp;为了方便对队列信息进行动态修改和发布，我们将队列的配置专门放到queues.xml中，并让messageContext去装载它。<br/>
&nbsp;&nbsp;queues.xml的路径配置在 conf/config.properties 中。当message.xml中不为messageContext注入targetQueueMap属性，messageContext将根据此配置去读取queues.xml<br/>
&nbsp;&nbsp;注：通常客户端所需的队列配置较少，可像上面的示例一样配置在message.xml中，而服务端的队列配置较多，且需要动态更新，放到queues.xml中更好。
<xmp>
	mq.conf.dir=d\:/temp/message/server
</xmp>
<h2><a name="amqServer"></a>服务端ActiveMQ配置</h2>
&nbsp;&nbsp;mac-message通过内嵌ActiveMQ来实现与ActiveMQ的集成，需要在spring配置文件中导入 activemq.xml<br/>
&nbsp;&nbsp;通过ActiveMQ 提供的拦截器，可以拦截输入到ActiveMQ的消息。<br/>
&nbsp;&nbsp;然后通过为 InterceptorPlugin 注入 converterMap 属性来指定要拦截的队列
<xmp>
	<broker xmlns="http://activemq.apache.org/schema/core" useJmx="false">
		<transportConnectors>
			<transportConnector uri="amqp://0.0.0.0:5672" />
			<transportConnector uri="tcp://0.0.0.0:61616" />
		</transportConnectors>
		<plugins>
			<discardingDLQBrokerPlugin dropAll="true"
				dropTemporaryTopics="true" dropTemporaryQueues="true" />

			<!-- ActiveMQ消息拦截器 -->
			<bean xmlns="http://www.springframework.org/schema/beans" class="com.boarsoft.message.amq.plugin.InterceptorPlugin">
				<property name="localMsgSvc1" ref="localMsgSvc1" />
				<!-- 消息转换器列表，用于将ActiveMQ消息转换为mac-message中定义的消息对象 -->
				<property name="converterMap">
					<map>
						<!-- Key为ActiveMQ中的队列名 -->
						<entry key="queue1">
							<bean class="com.boarsoft.boar.message.demo.AmqJsonMsgConverter" />
						</entry>
					</map>
				</property>
			</bean>
		</plugins>
	</broker>
</xmp>
<h2><a name="amqClient"></a>客户端ActiveMQ长连接配置</h2>
&nbsp;&nbsp;长连接方式需要在生产者和消费都都增加 activemq.xml，内容如下：
<xmp>
	<!-- 实现 javax.jms.Message 与 com.boarsoft.message.bean.Message 之间的互转 -->
	<bean id="msgConverter" class="com.boarsoft.message.demo.DemoJmsMsgConverter">
	</bean>

	<bean id="amqClient1" class="com.boarsoft.message.activemq.AmqClientEx">
		<property name="destMap">
			<map>
				<entry key="queue1">
					<bean class="com.boarsoft.boar.gateway.activemq.AmqDestination">
						<property name="producer">
							<bean class="com.boarsoft.message.activemq.AmqProducerEx">
								<property name="converter" ref="msgConverter" />
							</bean>
						</property>
						<property name="consumer">
							<bean class="com.boarsoft.message.activemq.AmqConsumerEx">
								<property name="converter" ref="msgConverter" />
								<property name="handler" ref="queue1Consumer1" />
							</bean>
						</property>
					</bean>
				</entry>
			</map>
		</property>
		<property name="connectionFactory">
			<bean class="org.apache.activemq.pool.PooledConnectionFactory">
				<property name="maxConnections" value="10" />
				<property name="connectionFactory">
					<bean class="org.apache.activemq.ActiveMQConnectionFactory">
						<property name="brokerURL"
							value="failover:(tcp://localhost:61616,tcp://127.0.0.1:61616)?randomize=true" />
						<property name="userName" value="admin" />
						<property name="password" value="admin" />
					</bean>
				</property>
			</bean>
		</property>
	</bean>
</xmp>
	</div>
</div>
<div id="foot">
Copyright © 2011. All rights reserved&nbsp;&nbsp;蜀ICP备11014774号-1&nbsp;&nbsp;
QQ: 7213571&nbsp;&nbsp;E-mail: pyh_jerry@163.com&nbsp;&nbsp;
<!-- 
<script type="text/javascript">
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3Ffc0b0282216be3d16055855d8c0e72d9' type='text/javascript'%3E%3C/script%3E"));
</script>
&nbsp;&nbsp;
 -->
</div></body>
</html>
